from apis.base import Base
from setting import LOGIN_INFO
from loguru import logger
from utils.object_utils import cache
import pytest
# 登录函数 ，


@pytest.fixture(scope='session',autouse=True)
def login():
    base = Base()

    # 调用登录接口
    login_url = base.get_url('/admin/auth/login')

    result = base.post(login_url,LOGIN_INFO)

    # 判断是否登录成功
    if not result.get('errno'):
        logger.success("请求登录接口成功")
        token = result.get('data').get('token')
        cache.set('token',token)
    else:
        logger.error("登录失败:{}".format(result))

    return result